

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { WheelSelector } from '@ionic-native/wheel-selector';

@Component({
  selector: 'page-atest',
 templateUrl: 'atest.html'
 
})


export class atestPage {
  jsonData = {
    numbers: [
      { description: "1" },
      { description: "2" },
      { description: "3" },
      { description: "4" },
      { description: "5" },
      { description: "6" },
      { description: "7" },
      { description: "8" },
      { description: "9" },
      { description: "10" }
    ],
    fruits: [
      { description: "Apple" },
      { description: "Orange" },
      { description: "Pear" },
      { description: "Banana" },
      { description: "Grapefruit" },
      { description: "Tangerine" }
    ],
    measurements: [
      { description: "Teaspoon" },
      { description: "Tablespoon" },
      { description: "Cup(s)" },
      { description: "Quart(s)" },
      { description: "Packages (7 oz)" },
      { description: "Packages (12 oz)" }
    ],
    planets: [
      { description: "Venus" },
      { description: "Jupiter" },
      { description: "Earth" },
      { description: "Pluto" },
      { description: "Neptune" }
    ],
    firstNames: [
      { name: "Fred", id: '1' },
      { name: "Jane", id: '2' },
      { name: "Bob", id: '3' },
      { name: "Earl", id: '4' },
      { name: "Eunice", id: '5' }
    ],
    lastNames: [
      { name: "Johnson", id: '100' },
      { name: "Doe", id: '101' },
      { name: "Kinishiwa", id: '102' },
      { name: "Gordon", id: '103' },
      { name: "Smith", id: '104' }
    ],
    uuids: [
      { id: "f70432b8-db2a-4cc3-a3a1-1e06c09cf814" },
      { id: "435e01f1-77c1-4154-9a2f-531b64297db2" },
      { id: "652b4ff5-c8a0-480e-bfd1-abb47c983914" },
      { id: "8ef9abe3-0968-4265-a6b2-dec270a85920" },
      { id: "c064fcb5-49e6-4976-bc60-c2eeda601f4b" }
    ],
  }

  selected: string;

  constructor(public navCtrl: NavController, public selector: WheelSelector) {
  }

  //more complex as overrides which key to display
  //then retrieve properties from original data
  selectNames() {
    this.selector.show({
      title: "Who?",
      items: [
        this.jsonData.firstNames, this.jsonData.lastNames
      ],
      displayKey: 'name',
      defaultItems: [
        {index: 0, value: this.jsonData.firstNames[2].name},
        {index: 1, value: this.jsonData.lastNames[3].name}
      ]
    }).then(
      result => {
        this.selected = result[0].name + ' (id= ' + this.jsonData.firstNames[result[0].index].id + '), ' +
          result[1].name + ' (id=' + this.jsonData.lastNames[result[1].index].id + ')';
      },
      err => console.log('Error occurred while getting result: ' + JSON.stringify(err))
      );
  }

  selectUuids() {
    this.selector.show({
      title: "Select a UUID",
      items: [
        this.jsonData.uuids
      ],
      displayKey: 'id'
    }).then(
      result => {
        this.selected = result[0].id;
      },
      err => console.log('Error occurred while getting result: ' + JSON.stringify(err))
      );
  }

  simpleFruit() {
    this.selector.show({
      title: "How Much?",
      items: [
        this.jsonData.numbers, this.jsonData.fruits
      ],
      positiveButtonText: "Ok",
      negativeButtonText: "Nope",
      wrapWheelText: true,
    }).then(
      result => {
        this.selected = result[0].description + ' ' + result[1].description;
      },
      err => console.log('Error occurred while getting result: ' + JSON.stringify(err))
      );
  }

  selectNumber() {
    this.selector.show({
      title: "How Many?",
      items: [
        this.jsonData.numbers
      ],
    }).then(
      result => {
        this.selected = result[0].description;
      },
      err => console.log('Error occurred while getting result: ', err)
      );
  }

  selectFruitQuantity() {
    this.selector.show({
      title: "How Many?",
      items: [
        this.jsonData.numbers,
        this.jsonData.measurements,
        this.jsonData.fruits
      ],
    }).then(
      result => {
        this.selected = result[0].description + ' ' + result[1].description + ' ' + result[2].description;
      },
      err => console.log('Error occurred while getting result: ', err)
      );
  }

  selectFruitQuantityFromPlanet() {
    this.selector.show({
      title: "How Many?",
      items: [
        this.jsonData.numbers,
        this.jsonData.measurements,
        this.jsonData.fruits,
        this.jsonData.planets
      ],
      wrapWheelText: true
    }).then(
      result => {
        this.selected = result[0].description + ' ' + result[1].description + ' ' + result[2].description + ' ' + result[3].description;
      },
      err => console.log('Error occurred while getting result: ', err)
      );
  }
  selectQuanity() {
    this.selector.show({
      title: "How Many?",
      items: [
        this.jsonData.numbers,
        this.jsonData.measurements
      ],
      wrapWheelText: true
    }).then(
      result => {
        this.selected = result[0].description + ' ' + result[1].description;
      },
      err => console.log('Error occurred while getting result: ', err)
      );
  }

  selectWithDefaultValues() {
    this.selector.show({
      title: "Default selected values should be: 3 Grapefruit",
      items: [
        this.jsonData.numbers,
        this.jsonData.fruits
      ],
      wrapWheelText: true,
      defaultItems: [
        {index:0 , value: "3"},
        {index:1 , value: "Grapefruit"}
        ]
    }).then(
      result => {
        this.selected = result[0].description + ' ' + result[1].description;
      },
      err => console.log('Error occurred while getting result: ', err)
      );
  }

  selectDefaultValuesThatDontExist(){
  this.selector.show({
      title: "Default selected values should be: 1 Apple",
      items: [
        this.jsonData.numbers,
        this.jsonData.fruits
      ],
      wrapWheelText: true,
      defaultItems: [
        {index:0 , value: "50"},
        {index:1 , value: "Kiwi"}
        ]
    }).then(
      result => {
        this.selected = result[0].description + ' ' + result[1].description;
      },
      err => console.log('Error occurred while getting result: ', err)
      );
  }
}
































// import { Component } from '@angular/core';
// import { } from '@ionic-native/core';
// import { WheelSelector } from '@ionic-native/wheel-selector';
// import { Platform, NavController, AlertController, NavParams, App } from 'ionic-angular';
// import { PubApi } from '../../providers/pubapi';


// import { Fun } from '../../providers/fun';
// import { returntaskPage } from '../returntask/returntask';//自由流程审批退回页面

// @Component({
//     selector: 'page-atest',
//     templateUrl: 'atest.html'
// })


// export class atestPage extends Fun {
//     public title: any = "进行段落首行文字缩进";//审批内容标题
//     public content: any = "我们利用DIV CSS text-indent进行段落首行文字缩进,DIVCSS5为大家介绍text-indent缩进语法结构,并通过案例示范图例教大家实现对文段首缩进样式";//审批内容
//     //  public EditDate:any;//新闻编辑日期
//     public Opinion: any;//批注
//     public WhetherAgree: any //是否同意
//     public data: any;
//     public model: any;
//     public fixed: boolean = true;  //是否是固定流程
//     public agree: boolean = true; //是否同意
//     user: any;//下一步处理者
//     dealc: any;//处理类型
//     jsonData: any;
//     constructor(private selector: WheelSelector, public platform: Platform, public alertCtrl: AlertController, public navCtrl: NavController, public navParams: NavParams, public appCtrl: App, public pubapi: PubApi) {
//         super(alertCtrl);
//         var that = this;

//         let jsonData = {
//             numbers: [
//                 { description: "1" },
//                 { description: "2" },
//                 { description: "3" }
//             ],
//             fruits: [
//                 { description: "Apple" },
//                 { description: "Banana" },
//                 { description: "Tangerine" }
//             ],
//             firstNames: [
//                 { name: "Fred", id: '1' },
//                 { name: "Jane", id: '2' },
//                 { name: "Bob", id: '3' },
//                 { name: "Earl", id: '4' },
//                 { name: "Eunice", id: '5' }
//             ],
//             lastNames: [
//                 { name: "Johnson", id: '100' },
//                 { name: "Doe", id: '101' },
//                 { name: "Kinishiwa", id: '102' },
//                 { name: "Gordon", id: '103' },
//                 { name: "Smith", id: '104' }
//             ]
//         };
//         this.jsonData = jsonData;

//         platform.ready().then(() => {
//             // this.model = navParams.get("items");
//             // this.title = this.model.Title;
//             this.pubapi.get("Users/GetAll", function (res) {
//                 that.user = res.data;
//             })
//             // this.content = //this.model.Description;
//         });
//     }

//     ionViewDidEnter() {
//         //this.showAlert("我们利用DIV CSS text-indent进行段落首行文字缩进");

//     }
//     //basic number selection, index is always returned in the result
//     selectANumber() {
//         this.selector.show({
//             title: "How Many?",
//             items: [
//                 this.jsonData.numbers
//             ],
//         }).then(
//             result => {
//                 console.log(result[0].description + ' at index: ' + result[0].index);
//             },
//             err => console.log('Error: ', err)
//             );
//     }


//     //basic selection, setting initial displayed default values: '3' 'Banana'
//     selectFruit() {
//         this.selector.show({
//             title: "How Much?",
//             items: [
//                 this.jsonData.numbers, this.jsonData.fruits
//             ],
//             positiveButtonText: "Ok",
//             negativeButtonText: "Nope",
//             defaultItems: [
//                 { index: 0, value: this.jsonData.numbers[2].description },
//                 { index: 1, value: this.jsonData.fruits[3].description }
//             ]
//         }).then(
//             result => {
//                 console.log(result[0].description + ' ' + result[1].description);
//             },
//             err => console.log('Error: ' + JSON.stringify(err))
//             );
//     }



//     //more complex as overrides which key to display
//     //then retrieve properties from original data
//     selectNamesUsingDisplayKey() {
//         this.selector.show({
//             title: "Who?",
//             items: [
//                 this.jsonData.firstNames, this.jsonData.lastNames
//             ],
//             displayKey: 'name',
//             defaultItems: [
//                 { index: 0, value: this.jsonData.firstNames[2].name },
//                 { index: 0, value: this.jsonData.lastNames[3].name }
//             ]
//         }).then(
//             result => {
//                 console.log(result[0].name + ' (id= ' + this.jsonData.firstNames[result[0].index].id + '), ' +
//                     result[1].name + ' (id=' + this.jsonData.lastNames[result[1].index].id + ')');
//             },
//             err => console.log('Error: ' + JSON.stringify(err))
//             );
//     }
//     approvalsubmit() {


//     }
// }

